import config from '@/config/config.js';
import http from "@/api/http.js";

const TemplateRequest ={
    loadTemplate(template,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/template/list?page="+page + "&limit="+limit;
            if(template){
                if (template.templateId){
                    url += "&detectionId=" + template.templateId;
                }
                if(template.templateName){
                    url += "&detectionName=" + template.templateName;
                }
                if (template.templateType){
                    url += "&defectType=" + template.templateType;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveTemplate(template,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/template/save";
            http.post(url,template,callBack);
        }else {
            callBack(undefined);
        }
    },
    deleteTemplate(templateId,callback){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/template/delete?templateId="+templateId;
            http.delete(url,callback)
        }else {
            callback(undefined);
        }
    },
    selectById(templateId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/template/get?templateId=" + templateId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateTemplateById(template,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/template/update";
            http.put(url,template,callBack);
        } else {
            callBack(undefined);
        }
    },




}

export default TemplateRequest
